Description: Lifecycle events trigger at different stages of a DC object when rendering, including construction, rendering, closing, and destruction, and these methods provide advanced functionality by controlling the order in which process handlers are run.

Note: Each property may be set declaratively when creating new DC objects, or directly by modifying individual properties on instantiated DC objects.

When an external JS resource is referenced using jsOnceBefore, jsBefore, jsAfter, or jsOnceAfter, the originating DC instance is automatically available within the external code using "DC". E.G. "DC.render();", "DC.remove();", amongst all DC API properties and methods. DC.props for example, will provide access to any custom data stored within the DC object. See the Props help file to see how to add custom data to a DC object.

Additionally, when external content is pulled into a DC object using the fetch object or DC.load() method, all embedded scripts within the external resources automatically have access to the originating DC instance using "DC". E.G. alert(DC.id);

Declarative Syntax

{
  EventName1: Function1,
  EventName2: Function2
  // Etc.
}

Direct Syntax

var Value = DC.PropertyName;

DC.EventName = function (arguments) {};

Lifecycle State Properties

// Reflects when the DC object is in the process of being rendered. True when loading, false otherwise.
  DC.loading

// Reflects when the DC object is completely rendered. True when rendered, false otherwise.
  DC.loaded

// Reflects when the DC object is in the process of being closed. True when closing, false otherwise.
  DC.closing

// Optionally abort the rendering of a DC object when in the process of loading.
// Must be set from within a lifecycle event, such as beforeRender, duringRender, or beforeRemove.
  DC.cancel = true

Lifecycle Events

// Execute when a DC object is instantiated as a live DC object.
// This event will fire regardless if the DC object is rendered or not.
  onCreate: function(DC) {   }

// Execute an array of external JS resources before a DC object opens.
// Only runs once.
  jsOnceBeforeRender: ["URL1.js", "URL2.js"]

// Execute before a DC object opens.
// Only runs once.
// Setting DC.cancel to true will abort rendering.
  onceBeforeRender: function(DC) {   }

// Execute an array of external JS resources before a DC object opens.
// Runs every time.
  jsBeforeRender: ["URL1.js", "URL2.js"]

// Execute before a DC object opens.
// Runs every time.
// Setting DC.cancel to true will abort rendering.
  beforeRender: function(DC) {   }

// Execute during the opening process of a DC object.
// Runs every time.
// Runs after all nodes are created, but just before the DOM rendering processes.
// Setting DC.cancel to true will abort rendering.
  duringRender: function(DC) {   }

// Execute an array of external JS resources after a DC object has opened.
// Only runs once.
  jsOnceAfterRender: ["URL1.js", "URL2.js"]

// Execute after a DC object has opened.
// Only runs once.
  onceAfterRender: function(DC) {   }

// Execute an array of external JS resources after a DC object has opened.
// Runs every time.
  jsAfterRender: ["URL1.js", "URL2.js"]

// Execute after a DC object has opened.
// Runs every time.
  afterRender: function(DC) {   }

// Execute before a DC object closes.
// Runs every time.
// Setting DC.cancel to true will abort closing.
  beforeRemove: function(DC) {   }

// Execute after a DC object is closed.
// Runs every time.
  afterRemove: function(DC) {   }

// Exicute before a DC object is destroyed.
// This only occurs when DC.destroy() or $A.destroy() is used to completely destroy a DC object.
  beforeDestroy: function(DC) {   }

// Exicute after a DC object is destroyed.
// This only occurs when DC.destroy() or $A.destroy() is used to completely destroy a DC object.
  afterDestroy: function() {   }

Special Properties

// Reverse the external JavaScript execution order.
// When true, external JS scripts will run after the associated inline scripts instead of before, as they do by default.
// E.G This means, jsBefore will exicute after beforeRender, instead of the other way around as shown above.
// This reversal will occur for all lifecycle events that include the exicution of external scripts.
  reverseJSOrder: false

// Allow for the cascading of lifecycle events when multiple events of the same type are declared.
// When true, lifecycle events with the same name declared as overrides when instantiating DC objects using $A(), will exicute in succession instead of being overwritten.
// The same is true when setting a globalDC lifecycle method using $A.setGlobal(),
// which will exicute in the order: first the individual DC method, followed by the shared method, followed by the globalDC method.
// This allows for a afterRender function to be executed on a DC object, a different afterRender function to be executed on all DC objects within the same DC.sibling array, and a different afterRender function to be executed on all DC objects everywhere.
  allowCascade: true
